package com.hexb.smh.entity.param.account;

import com.hexb.core.exception.BusinessException;
import com.hexb.core.utils.RSAUtils;
import com.hexb.smh.errors.ErrorCodes;
import com.hexb.smh.utils.SmhConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * @Package : com.hexb.smh.entity.param
 * @Author : hexb
 * @Date : 2020-08-17 22:47
 */
@Data
public class PasswordModifierParam {
    @ApiModelProperty("旧密码(需要加密)")
    @NotNull
    @Size(min = 6)
    private String oldPassword;

    @ApiModelProperty("新密码(需要加密)")
    @NotNull
    @Size(min = 6)
    private String newPassword;

    public String getOldPassword() {
        try {
            return RSAUtils.decryptByPrivateKey(oldPassword, SmhConstant.RSA_PRIVATE);
        } catch (Exception e) {
            throw new BusinessException(ErrorCodes.INVALID_ENCRYPT_CONTENT);
        }
    }

    public String getNewPassword() {
        try {
            return RSAUtils.decryptByPrivateKey(newPassword, SmhConstant.RSA_PRIVATE);
        } catch (Exception e) {
            throw new BusinessException(ErrorCodes.INVALID_ENCRYPT_CONTENT);
        }
    }
}
